//1. require the highlight.js library including all languages
const hljs = require('highlight.js');
const highlightedCode = hljs.highlightAuto('<span>Hello World!</span>').value
console.log('highlightedCode:',highlightedCode);
// highlightedCode:
/*
<span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Hello World!<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
* */


//2. To load only a “common” subset of popular languages:
// const hljs = require('highlight.js/lib/common');


//3. To highlight code with a specific language, use highlight:
//const html = hljs.highlight('<h1>Hello World!</h1>', {language: 'xml'}).value


//3. require the highlight.js library without languages
const hljs = require("highlight.js/lib/core");
// separately require languages
hljs.registerLanguage('html', require('highlight.js/lib/languages/html'));
hljs.registerLanguage('sql', require('highlight.js/lib/languages/sql'));
// highlight with providing the language
const highlightedCode = hljs.highlight('html', '<span>Hello World!</span>'/*,ignore_illegals:true*/).value;

/*
ignore_illegals:
The ignore_illegals parameter, when present and evaluates to a true value, forces highlighting to finish even in case of detecting illegal syntax for the language instead of throwing an exception

如果ignore_illegals为true 则即使你 fenced blocks里的代码的语法不符合你指定的语言 也不会抛出异常 而是强制解析
*/


/*
To set the syntax highlighting style, if your build tool processes CSS from your JavaScript entry point, you can import the stylesheet directly into your CommonJS-module:
*/
// import 'highlight.js/styles/github.css';
